package edu.suda.xsap.service.impl;

import edu.suda.xsap.dto.MemberDto;
import edu.suda.xsap.dto.convert.MemberConvert;
import edu.suda.xsap.entity.Member;
import edu.suda.xsap.mapper.MemberMapper;
import edu.suda.xsap.service.MemberService;
import edu.suda.xsapadminutils.common.Result;
import edu.suda.xsapadminvo.MemberVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Service
public class MemberServiceImpl implements MemberService {

    @Autowired
    private MemberMapper memberMapper;

    @Autowired
    private MemberConvert memberConvert;

    @Override
    public Result save(@RequestBody MemberVO memberVO) {
        memberMapper.save(memberVO);
        return Result.success();
    }

    @Override
    public List<MemberDto> findAll() {
        List<Member> members = memberMapper.findAll();
        return memberConvert.toDtoList(members);
    }

    @Override
    public Result update(@RequestBody MemberVO memberVO) {
        memberMapper.update(memberVO);
        return Result.success();
    }

    @Override
    public Result delete(@RequestBody MemberVO memberVO) {
        memberMapper.delete(memberVO);
        return Result.success();
    }

}
